//
//  YSMeViewController.m
//  YouSheng
//
//  Created by aaa on 16/8/17.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "YSMeViewController.h"
#import "MeTopView.h"
#import "YSMeBtn.h"
#import "YSMeYuViewController.h"
#import "YSMeBianJiViewController.h"
#import "YSMeCzViewController.h"
#import "YSMeYaoCzViewController.h"
#import "YSMeZhangDanViewController.h"
#import "YSQRCodeViewController.h"
#import "YSMeSaoMiaoViewController.h"

#define YSBJColorHui [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1]

@interface YSMeViewController ()<MeTopViewDelegate>

//头部view
@property(nonatomic,weak) MeTopView *topView;
//存按钮图标的数组
@property(nonatomic,strong) NSArray *btnIconArr;
//存按钮名字的数组
@property(nonatomic,strong) NSArray *btnNameArr;
@end

@implementation YSMeViewController

#pragma mark - 懒加载
- (NSArray *)btnIconArr {
    if (!_btnIconArr) {
        _btnIconArr = @[@"me_xxtz",@"me_qianbao",@"me_zdmx",@"me_chongzhi",@"me_saomiao",@"me_bzzx",@"me_shezhi"];
    }
    return _btnIconArr;
}

- (NSArray *)btnNameArr {
    if (!_btnNameArr) {
        _btnNameArr = @[@"消息通知",@"我的钱包",@"账单明细",@"我要充值",@"扫描二维码",@"帮助中心",@"设置"];
    }
    return _btnNameArr;
}

#pragma mark - 入口
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = YSBJColorHui;

    //添加头部view
    [self setupTopView];
    //添加下部按钮
    [self setupBottomBtn];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

//添加头部view
- (void)setupTopView {
    MeTopView *topView = [MeTopView topView];
    topView.delegate = self;
    self.topView = topView;
    topView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300);
    [self.view addSubview:topView];
}

//添加下部按钮
- (void)setupBottomBtn {
    for (int i = 0; i < self.btnNameArr.count; i++) {
        //按钮
        NSInteger margin = 10;
        NSInteger w = self.view.bounds.size.width;
        NSInteger h = 40;
        NSInteger x = 0;
        NSInteger y = self.topView.bounds.size.height + margin + i * h;
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        YSMeBtn *btn = [[YSMeBtn alloc] init];
//        btn.imageView.backgroundColor = [UIColor redColor];
        if (i > 3) {
            btn.frame = CGRectMake(x, y + 10 + i * 0.3, w, h);
        }else {
            btn.frame = CGRectMake(x, y + i * 0.3, w, h);
        }
        btn.tag = i;
        [btn addTarget:self action:@selector(meBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        //添加左边图片
        UIImageView *iconV = [[UIImageView alloc] init];
        iconV.frame = CGRectMake(10, 5, 30, 30);
        iconV.image = [UIImage imageNamed:self.btnIconArr[i]];
        NSLog(@"%@------------",self.btnIconArr);
        [btn addSubview:iconV];
        
        //添加右边图片
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bj_jiantou"]];
        imgV.frame = CGRectMake(340, 0, 25, 35);
        [btn addSubview:imgV];
        
//        [btn setImage:[UIImage imageNamed:self.btnIconArr[i]] forState:UIControlStateNormal];
        btn.imageView.image = [UIImage imageNamed:self.btnIconArr[i]];
        [btn setTitle:self.btnNameArr[i] forState:UIControlStateNormal];
        
        
        [self.view addSubview:btn];
    }
}

//按钮点击
- (void)meBtnClick:(UIButton *)button {
    if (button.tag == 0) {
        
    }else if (button.tag == 1) {
        YSMeYuViewController *yuVC = [[YSMeYuViewController alloc] init];
        yuVC.title = @"我的钱包";
        [self.navigationController pushViewController:yuVC animated:YES];
    }else if (button.tag == 2) {
        YSMeZhangDanViewController *zdVC = [[YSMeZhangDanViewController alloc] init];
        zdVC.title = button.titleLabel.text;
        [self.navigationController pushViewController:zdVC animated:YES];
    }else if (button.tag == 3) {
//        YSMeCzViewController *czVC = [[YSMeCzViewController alloc] init];
//        [self.navigationController pushViewController:czVC animated:YES];
//        czVC.titleName = button.titleLabel.text;
        YSMeYaoCzViewController *yczVC = [[YSMeYaoCzViewController alloc] init];
        yczVC.navTitle = button.titleLabel.text;
        [self.navigationController pushViewController:yczVC animated:YES];

    }else if (button.tag == 4) {
        YSMeSaoMiaoViewController *smVC = [[YSMeSaoMiaoViewController alloc] init];
        smVC.title = button.titleLabel.text;
        [self.navigationController pushViewController:smVC animated:YES];
        
    }else if (button.tag == 5) {
        
    }else if (button.tag == 6) {
        
    }
}

#pragma mark - MeTopViewDelegate
- (void)meTopViewClickYeBtn {
    YSMeYuViewController *yuVC = [[YSMeYuViewController alloc] init];
    yuVC.title = @"我的钱包";
    [self.navigationController pushViewController:yuVC animated:YES];
}

- (void)meTopViewClickQRCodeBtn {
    YSQRCodeViewController *QRCodeVC = [[YSQRCodeViewController alloc] init];
    QRCodeVC.title = @"我的二维码";
    QRCodeVC.ewmString = self.topView.nameLabel.text;
    [self.navigationController pushViewController:QRCodeVC animated:YES];
}

- (void)meTopViewClickBjBtn {
    YSMeBianJiViewController *bjVC = [[YSMeBianJiViewController alloc] init];
    bjVC.title = @"编辑资料";
    bjVC.userName = self.topView.nameLabel.text;
    [self.navigationController pushViewController:bjVC animated:YES];
}

@end
